typedef struct node{
	int id;
	int val;
	bool operator < (const node& n) const {
		return val < n.val;
	}
}node;

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
	node nodes[nums.size()];
	int length = nums.size();
	vector<int> temp; 
	for (int i = 0; i < length; ++i) {
		nodes[i].id = i;
		nodes[i].val = nums[i];
	}
	sort(nodes, nodes + nums.size());
	int lo = 0;
	int hi = nums.size() - 1;
	while (lo < hi) {
		if (nodes[lo].val + nodes[hi].val == target)
			break;
		if (nodes[lo].val + nodes[hi].val < target)
			++lo;
		if (nodes[lo].val + nodes[hi].val > target)
			--hi;
	} 
	temp.push_back(min(nodes[lo].id, nodes[hi].id));
	temp.push_back(max(nodes[lo].id, nodes[hi].id));
	return temp;
    }
};